<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" >
<head th:include="admin/common/resource ::commonHead('首页')" ></head>
    <body  style="margin: 0px;padding: 0px" >
        <div class="container-fluid">
            <div class="toolbar btn-group-sm" banner="toolbar" >
                <h6 style="margin-top: 10px;margin-bottom: 20px" > 后台管理系统 / Banner管理 / Banner列表 </h6>
                <div style="margin-bottom: 10px;" >
                    <button shiro:hasPermission="banner:add" onclick="loadPage('/admin/banner/add')" type="button" class="btn btn-sm btn-success"> 添加Banner </button>
                    <button type="button" class="btn btn-sm btn-primary"> 导出 </button>
                </div>
            </div>
            <table class="table">
                <thead>
                <tr>
                    <th scope="col"> ID </th>
                    <th scope="col"> Banner名 </th>
                    <th scope="col"> Banner图 </th>
                    <th scope="col"> 创建时间 </th>
                    <th scope="col"> 状态 </th>
                    <th scope="col"> 操作 </th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="banner:${pager.list}" >
                    <th scope="row" th:text="${banner.id}" ></th>
                    <td th:text="${banner.name}"></td>
                    <td >
                        <img style="height: 60px" th:src="${imageService+banner.url}" alt="">
                    </td>
                    <td th:text="${#dates.format(banner.createTime,'yyyy-MM-dd HH:mm')}" ></td>
                    <td th:text="${banner.status} == 1?'正常':'异常'"></td>
                    <td>
                        <a shiro:hasPermission="banner:edit" class="btn-outline-primary" th:href="@{'/admin/banner/edit?id='+${banner.id}}">编辑</a>
                        <a shiro:hasPermission="banner:delete" class="btn-outline-danger" th:href="@{'javascript:destroy('+${banner.id}+')'}">删除</a>
                    </td>
                </tr>
                </tbody>
            </table>
            <!-- 分页 -->
            <div th:replace="admin/common/pager ::page_pager(${pager.currentPage},0,${pager.totalPage}, @{/admin/banner/list})"></div>
        </div>
    </body>
<div th:include="admin/common/resource ::footerJs"></div>
<script th:src="@{/layui/layui.all.js}"></script>
<script>


    function destroy(id){
        layer.confirm('真的删除这个分类吗?', function(index){
            layer.close(index);
            //向服务端发送删除指令
            $.ajax({
                type:'delete',
                url: "/admin/banner/delete",
                data: {
                    id: id
                },
                success: function (data) {
                    console.log(data);
                    if(data.status == 1){
                        layer.msg("成功",function () {
                            window.location.reload();
                        },2000)
                    }else{
                        layer.msg("失败")
                    }
                }
            })
        });
    }
</script>
</html>
